| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import { NextRequest, NextResponse } from "next/server";
- import { restApiFetch } from "@/utils/bagisto";
- import { isBagistoError } from "@/utils/type-guards";
- import { getAuthToken } from "@/utils/helper";
- type Params = Promise<{ id: string }>;
- export async function GET(req: NextRequest, { params }: { params: Params }) {
- try {
- const { id } = await params; // 解包拿到订单ID
- const guestToken = getAuthToken(req);
- const apiUrl = `/customer/orders/${id}`;
- console.log("最终请求API地址:", apiUrl);
- const response = await restApiFetch<any>({
- api: apiUrl,
- method: "GET",
- cache: "no-store",
- guestToken,
- });
- return NextResponse.json({
- status: response.status,
- data: response.body,
- });
- } catch (error) {
- if (isBagistoError(error)) {
- return NextResponse.json(
- {
- data: null,
- error: error.cause ?? error,
- },
- { status: 200 }
- );
- }
- return NextResponse.json(
- {
- message: "Network error",
- error: error instanceof Error ? error.message : error,
- },
- { status: 500 }
- );
- }
- }
|